package com.exam.sacrifice.ui.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.exam.sacrifice.R;
import com.exam.sacrifice.ui.bean.BaiJiaXingInfo;

public class BaiJiaXingListAdapter extends BaseQuickAdapter<BaiJiaXingInfo, BaseViewHolder> {

    private OnItemClickListener listener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        listener = onItemClickListener;
    }

    public BaiJiaXingListAdapter() {
        super(R.layout.item_layout_baijiaxing_list, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, BaiJiaXingInfo item) {

        helper.setText(R.id.tv_name, item.surname);
        helper.setText(R.id.tv_paiming, String.format("排名：%d", helper.getAdapterPosition() + 1));

        StringBuilder stringBuilder = new StringBuilder();
        String zupuStr = item.surname + "族谱";
        for (int i = 0; i < zupuStr.length(); i++) {
            if (stringBuilder.length() > 0) {
                stringBuilder.append("\n");
            }
            stringBuilder.append(zupuStr.charAt(i));
        }
        helper.setText(R.id.tv_xingshi, stringBuilder.toString());

        helper.itemView.setOnClickListener(v -> {
            if (listener != null) {
                listener.onItemClick(item);
            }
        });
    }

    public interface OnItemClickListener {
        void onItemClick(BaiJiaXingInfo item);
    }
}
